﻿Public Class frmFactura 
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            'PanelArriba.Enabled = True
            'PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            'PanelArriba.Enabled = False
            'PanelAbajo.Enabled = True
        End If
    End Sub

    Private Sub FacturasBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles FacturasBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.FacturasBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub frmFactura_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empresas' table. You can move, or remove it, as needed.
        Me.EmpresasTableAdapter.Fill(Me.DbFireAndIceDataSet.empresas)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.vClientes' table. You can move, or remove it, as needed.
        Me.VClientesTableAdapter.Fill(Me.DbFireAndIceDataSet.vClientes)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.clientes' table. You can move, or remove it, as needed.
        Me.ClientesTableAdapter.Fill(Me.DbFireAndIceDataSet.clientes)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.vfactdetalle' table. You can move, or remove it, as needed.
        Me.VfactdetalleTableAdapter.Fill(Me.DbFireAndIceDataSet.vfactdetalle)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.tipospago' table. You can move, or remove it, as needed.
        Me.TipospagoTableAdapter.Fill(Me.DbFireAndIceDataSet.tipospago)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.itemventa' table. You can move, or remove it, as needed.
        Me.ItemventaTableAdapter.Fill(Me.DbFireAndIceDataSet.itemventa)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.facturasdetalle' table. You can move, or remove it, as needed.
        Me.FacturasdetalleTableAdapter.Fill(Me.DbFireAndIceDataSet.facturasdetalle)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.facturas' table. You can move, or remove it, as needed.
        Me.FacturasTableAdapter.Fill(Me.DbFireAndIceDataSet.facturas)
        BindingNavigatorAddNewItem.PerformClick()
    End Sub

    Private Sub SimpleButton1_Click(sender As System.Object, e As System.EventArgs)
        My.Forms.factSeleccionarItem.Show()
    End Sub

    Private Sub TextEdit4_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles TextEdit4.EditValueChanged
        If Not IsDBNull(IdclienteTextEdit1.EditValue) Then
            PrecioventaTextEdit.EditValue = TextEdit4.GetColumnValue("precioventa")
        End If
    End Sub

    Private Sub SimpleButton1_Click_1(sender As System.Object, e As System.EventArgs) Handles SimpleButton1.Click
        If TextEdit4.Text.Length = 0 Then
            ErrorProvider1.SetError(TextEdit4, "Debe ingresar un Item de Venta")
        ElseIf PrecioventaTextEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(PrecioventaTextEdit, "Debe ingresar un precio de venta")
        ElseIf tcantidad.Text.Length = 0 Then
            ErrorProvider1.SetError(tcantidad, "Debe ingresar una cantidad")
        Else
            ErrorProvider1.SetError(TextEdit4, Nothing)
            ErrorProvider1.SetError(PrecioventaTextEdit, Nothing)
            ErrorProvider1.SetError(tcantidad, Nothing)

            'TipospagoBindingNavigatorSaveItem.PerformClick()
            MessageBox.Show("Se guardó el resgistro satisfactoriamente")
            Mostrar()
        End If
    End Sub

    Private Sub IdclienteTextEdit1_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles IdclienteTextEdit1.EditValueChanged
        If Not IsDBNull(IdclienteTextEdit1.EditValue) Then
            ClienteTextEdit.EditValue = IdclienteTextEdit1.GetColumnValue("idcliente")
            IdempresaTextEdit.EditValue = IdclienteTextEdit1.GetColumnValue("idempresa")
            subsidiootorgado.EditValue = IdclienteTextEdit1.GetColumnValue("montosubsidio")
            subsidiodisp.EditValue = "23"
        End If
    End Sub

    Private Sub PrecioventaTextEdit_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles PrecioventaTextEdit.EditValueChanged
        If Not IsDBNull(PrecioventaTextEdit.EditValue) And Not IsDBNull(tcantidad.EditValue) Then
            ttotallinea.EditValue = Val(PrecioventaTextEdit.EditValue) * Val(tcantidad.EditValue)
        End If
    End Sub

    Private Sub tcantidad_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles tcantidad.EditValueChanged
        If Not IsDBNull(PrecioventaTextEdit.EditValue) And Not IsDBNull(tcantidad.EditValue) Then
            ttotallinea.EditValue = Val(PrecioventaTextEdit.EditValue) * Val(tcantidad.EditValue)
        End If
    End Sub

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub ClienteTextEdit_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles ClienteTextEdit.EditValueChanged
        If Not IsDBNull(ClienteTextEdit.EditValue) Then
            IdclienteTextEdit1.EditValue = ClienteTextEdit.GetColumnValue("idcliente")
            IdempresaTextEdit.EditValue = ClienteTextEdit.GetColumnValue("idempresa")
            subsidiootorgado.EditValue = ClienteTextEdit.GetColumnValue("montosubsidio")
        End If
    End Sub

    Private Sub BarButtonItem1_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
        'login.Show()
        MessageBox.Show("Aqui iria algo parecido al login ;)")
    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If IdclienteTextEdit1.Text.Length = 0 Then
            ErrorProvider1.SetError(IdclienteTextEdit1, "Debe ingresar un nombre para el Cliente")
        ElseIf IdempresaTextEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(IdempresaTextEdit, "Debe ingresar un nombre para la Empresa")
        ElseIf IdempleadoTextEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(IdempleadoTextEdit, "Debe ingresar un nombre para el Empleado")
        Else
            ErrorProvider1.SetError(IdclienteTextEdit1, Nothing)
            ErrorProvider1.SetError(IdempresaTextEdit, Nothing)
            ErrorProvider1.SetError(IdempleadoTextEdit, Nothing)

            'TipospagoBindingNavigatorSaveItem.PerformClick()
            MessageBox.Show("Se guardó el resgistro satisfactoriamente")
            Mostrar()
        End If
    End Sub
End Class